
import threading
from aioredis import Redis
from redis import Redis
from fastapi import APIRouter, Depends
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from initialization.dbInit import get_db_session
from initialization.redisInit import get_async_redis, get_sync_redis
from model.entitys import get_sync_db, SyncSession, CaseGroup
from service import debugService

debug = APIRouter(tags=["任务管理"])

count = 0

@debug.post("/debug/addSchedTest")
def addSchedTest(sync_db: AsyncSession = Depends(get_sync_db), sync_redis: Redis = Depends(get_sync_redis)):
# async def addSchedTest(session: AsyncSession = Depends(get_db_session), async_redis: Redis = Depends(get_async_redis)):
# async def addSchedTest(async_redis: Redis = Depends(get_sync_redis)):
    # print("async_redis：", async_redis)

    print("sync_db：", sync_db)
    print("sync_redis：", sync_redis)
    print("value：", sync_redis.get("31d3d6d0-db35-11ec-85dd-1c697ac9cfe3"))
    sync_redis.delete("31d3d6d0-db35-11ec-85dd-1c697ac9cfe3")
    print("value：", sync_redis.get("31d3d6d0-db35-11ec-85dd-1c697ac9cfe3"))

    # case_group_id_list = (await session.execute(select(CaseGroup.id))).scalars().all()
    # print("case_group_id_list：", case_group_id_list)
    # await session.close()

    # await async_redis.set("key1", "7657hgfvjhghjfgh")
    # await async_redis.set("key2", "06478676")
    # await async_redis.set("key3", "&*$#%R^&")
    # await async_redis.set("key4", "nhjfghfgjbcfh")
    #
    # print(
    #     await async_redis.get("key1"),
    #     await async_redis.get("key2"),
    #     await async_redis.get("key3"),
    #     await async_redis.get("key4")
    # )
    #
    # keys = ["key1", "key2", "key3", "key4"]
    # await async_redis.delete(*keys)
    #
    # print(
    #     await async_redis.get("key1"),
    #     await async_redis.get("key2"),
    #     await async_redis.get("key3"),
    #     await async_redis.get("key4")
    # )
    # await async_redis.close()

    sync_redis.set("key1", "7657hgfvjhghjfgh")
    sync_redis.set("key2", "06478676")
    sync_redis.set("key3", "&*$#%R^&")
    sync_redis.set("key4", "nhjfghfgjbcfh")

    print(
        sync_redis.get("key1"),
        sync_redis.get("key2"),
        sync_redis.get("key3"),
        sync_redis.get("key4")
    )

    keys = ["key1", "key2", "key3", "key4"]
    sync_redis.delete(*keys)

    print(
        sync_redis.get("key1"),
        sync_redis.get("key2"),
        sync_redis.get("key3"),
        sync_redis.get("key4")
    )
    sync_redis.close()

    return debugService.add_sched_test()

    # global count
    # if count > 5:
    #     return {"message": "不允许继续操作", "code": 200, "data": None}
    #
    # count += 1
    # print("count：", count)
    #
    # await async_redis.set("async_redis", "async_redis     异步redis插入值给同步redis取")
    #
    # ex = await async_redis.exists("async_redis")
    # if ex:
    #     print("找到了。。。。。。。。。。。。。。。。。。。。。。")
    # print("ex：", ex)
    #
    # threading.Thread(target=debugService.async_test, args=()).start()

    # debugService.async_test()

    # return debugService.async_test()

    return {"message": "操作成功", "code": 200, "data": None}


















































